Introduction to GitHub and Version Control
Assistant Professor at Charles University
Head of 🧑💻Laboratory of Quantitative Ecology
🕵️Who is here?
Graph created based on questionnaire | Image generated by ChatGPT
😸Code on GitHub: OndrejMottl/VersionControl_Mendel_Apr2025
🖼️Slides: bit.ly/mottl_prez_20250424
It is all about keeping track of changes 📓✍️
03:00
Each “paper” is a single project.
R-studio is using Projects already by default
Follow instructions in Version Control - git hell (a separate presentation).
Getting all the necessary software installed, configured, and playing nicely together is honestly half the battle … Brace yourself for some pain
You will still need to know the basics of shell.
GUI = Graphical User Interface
I will be showing you how to use:
The {usethis} package is a collection of functions that help various tasks in R.
Install the package by running:
call a function by running:
Activate git for a repo
Create new project with git tracking
Git integration is automatic in Source control panel
05:00 A commit is a record of a change
If you create or edit a file in your repository and save the changes, you need to record your change via a commit
Chess move diary:
Pawn to d4
Edit line 32 of file A
Make a change to a file and save it. Now stage the change:
05:00 Commit (record) staged changes:
$ git log --stat
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
Remove unnecessary test
lib/simplegit.rb | 5 -----
1 file changed, 5 deletions(-)
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
Initial commit
README | 6 ++++++
Rakefile | 23 +++++++++++++++++++++++
lib/simplegit.rb | 25 +++++++++++++++++++++++++
3 files changed, 54 insertions(+)SHA - unique identifier
Author - who has done this?
Date - when was this done?
Message - description of what has been done
Stats - what has changed?
05:00 Commits are quick and cheap. Therefore:
Now we need to sync chnages with the remote using PUSH
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
05:00 Now we need to sync chnages from the remote to local the using PULL
README - description of the project
.gitignore - list of files ignored by GitHub (more about it later)
license - tell other what they can do wit your code
Create a new repo on GitHub
05:00 Copy (download) from remote repo to local machine
Example of online repo: OndrejMottl/VersionControl-playground
Clone repo using new project in RStudio GUI or via {usethis} package:
Open Command Palette (Ctrl+Shift+p)
Paste in URL: "https://github.com/<OWNER>/<REPO>.git"
clone a repo (e.g. any repo from OndrejMottl)
05:00 A merge conflict can occur when you are changing the same line in one file differently.
To https://github.com/picardis/myrepo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/picardis/myrepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.a good strategy to avoid such conflicts:
Merge conflicts cannot always be avoided (but can be mitigated by branches; later).
How to undo last commit?
Variant A: I commited but NOT pushed yet.
RStudio has a range of possibilities to work with Git and GitHub as shown in this tutorial. The Terminal (NOT console) has more commands and options and will be handy for trouble shooting.
Open Command Palette (Ctrl+Shift+p)
Write Git: Undo Last Commit
How to undo last commit?
Variant B: I commited but AND pushed already.
Right-click on the commit you would like to undo to and select Revert a commit.
In the Source control panel -> COMMITS section -> Right-click on the commit you want to revert to -> Select the Reset Current Branch to Previous Commit
The default branch is called main or master
Swithching between branches is sometimes called (checkout)
‼️ Make sure that you have all changes commited before switching ‼️
05:00 Request to merge a branch
After you push new branch, you should have a green button Compare & pull request on GitHub
Now you can more commits on GitHub, (add Comment to start discussion), or merge the branch.
25:00 You can use Markdown on GitHub in the description and comments
More details on Github Docs
A tool to review on GitHub suggested changes
On someone else’s PR on GitHub, you can comment on individual lines or whole files
Merge conflict with branches is much more pleasant😎
Edit the file as needed
Commit the changes
Merge a branch
05:00 We can delete branch directly on GitHub after merging
We can also delete branch before merging
We need the Terminal (NOT console) again.
To delete a local branch
To delete a remote on GitHub branch
To delete a local branch
To delete a remote on GitHub branch
Open Command Palette (Ctrl+Shift+p)
Select Git: Delete branch …
Delete a branch
05:00
Introduction to GitHub and Version Control
27.3.2025